package me.lijf.xapi.controller;

import lombok.extern.slf4j.Slf4j;
import me.lijf.xapi.dto.RestResponse;
import me.lijf.xapi.exception.XException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@Slf4j
@ControllerAdvice
public class XExceptionHandler {
    @ExceptionHandler(value =Exception.class)
    @ResponseBody
    public Object handler(Exception e){
        e.printStackTrace();
        if(e instanceof XException) return RestResponse.fail(((XException) e));
        return RestResponse.fail(new XException(500,e.getMessage()));
    }
}
